package items
{
	import org.flixel.*;
	
	import projectiles.*;
	
	/**
	 * ...
	 * @author JAC
	 */
	public class RockThrow extends Item
	{
		public function RockThrow(i:uint = 0, j:uint = 0)
		{
			super(i, j);
			
			_duration = 1;
			
			loadGraphic(Assets.ImgItemBoulder);
			
			toggleLight();
		}
		
		override public function onUse(p:Player):Boolean
		{
			super.onUse(p);
			
			var rock:Rock = new Rock();
			rock.translateToTileByPoint(p.getMidpoint());
			rock.launch(UP);
			
			rock = new Rock();
			rock.translateToTileByPoint(p.getMidpoint());
			rock.launch(DOWN);
			
			rock = new Rock();
			rock.translateToTileByPoint(p.getMidpoint());
			rock.launch(LEFT);
			
			rock = new Rock();
			rock.translateToTileByPoint(p.getMidpoint());
			rock.launch(RIGHT);
			
			FlxG.play(Assets.SndRockThrow, Registry.soundVolume);
			
			_timer.reset(1);
			
			return true;
		}
		
		override public function update():void
		{
			super.update();
			
			if (_used)
			{
				if (_timer.hasExpired)
				{
					destroy();
				}
				
				if (!Player.isAlive)
				{
					destroy();
				}
			}
		}
	}
}